<%@ tag language="java" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<%@ attribute name="id" type="java.lang.String" required="true" description="唯一编号"%>
<%@ attribute name="name" type="java.lang.String" required="true" description="隐藏的名称（用于Input的表单提交）"%>
<%@ attribute name="value" type="java.lang.String" required="true" description="隐藏的名称的值"%>
<%@ attribute name="prePath" type="java.lang.String" required="false" description="保存到服务器时文件前缀文件夹"%>
<%@ attribute name="fileUrl" type="java.lang.String" required="false" description="文件的URL"%>
<div class="row">
	<div class="col-sm-4">
		<button id="${id}UploadBtn" type="button"  class="btn btn-info">&nbsp;选择&nbsp;</button>
		<input id="${id}UploadInput" type="hidden" name="${name}" value="${value}"/>
		<input id="${id}UploadFile" style="display: none" type="file" name="${id}Upfile" onchange="uploadFile${id}Fun()"/>  
	</div>
	<div class="col-sm-8" id="${id}UploadDiv">
		<c:if test="${not empty fileUrl}">
			<a href="${fileUrl}" target="_blank"><img src="${fileUrl}" width="50" height="50"></a>
		</c:if>
	</div>
</div>
<script type="text/javascript">
function uploadFile${id}Fun(){ 
	var index=layer.load(1, {
	    shade: [0.3,'#000'] //0.1透明度的白色背景
	});
    $.ajaxFileUpload({  
        url:'${ctx}/resource/upload',  
        secureuri:false,  
        fileElementId:'${id}UploadFile',//file标签的id  
        dataType: 'json',//返回数据的类型  
        data:{name:'${id}Upfile',prePath:"${prePath}"},//一同上传的数据  
        success: function (data, status) {
        	layer.close(index); 
        	if(data.code=="200"){
	            $("#${id}UploadDiv").html('<a href="'+data.data.fileUrl+'" target="_blank"><img src="'+data.data.fileUrl+'" width="50" height="50"></a>');
	            $("#${id}UploadInput").val(data.data.filePath);
        	}else{
        		alert(data.msg);
        	}
        },  
        error: function (data, status, e) { 
        	layer.close(index); 
            alert(e);  
        }  
    });  
}
$(function(){  
    $("#${id}UploadBtn").on('click', function() {  
        $('#${id}UploadFile').click();  
    });  
 });   
</script>